<template>
  <div>
    <!-- 面包鞋导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 主体区域 -->
    <el-card>
      <!-- 搜索框 -->
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入关键字"
            v-model="queryInfo.query"
            clearable
            @clear="getAllOrderList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getAllOrderList"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 数据列表 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column
          label="订单价格(元)"
          prop="order_price"
          width="100px"
        ></el-table-column>
        <el-table-column label="付款状态" width="80px">
          <template v-slot="scope">
            <el-tag v-if="scope.row.pay_status" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="发货状态"
          prop="is_send"
          width="80px"
        ></el-table-column>
        <el-table-column label="下单时间" width="150px">
          <template v-slot="scope">
            <span>{{ scope.row.create_time | dateFormat }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        @size-change="pageSizeChange"
        @current-change="pageNumChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      total: 0,
      orderList: [],
    };
  },
  methods: {
    // 获取订单列表
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);

      this.orderList = res.data.goods;
      this.total = res.data.total;

      console.log(this.orderList);
    },
    pageSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    pageNumChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOrderList();
    },
    getAllOrderList() {
      this.queryInfo.pagenum = 1;
      console.log(this.queryInfo);
      this.getOrderList();
    },
  },
  created() {
    this.getOrderList();
  },
};
</script>
<style lang='less' scoped>
</style>